package com.qk.controller;

import com.qk.common.Result;
import com.qk.entity.Activity;
import com.qk.entity.PageResult;
import com.qk.service.ActivityService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/activities")
public class ActivityController {
    @Autowired
    private ActivityService activityService;
    @GetMapping
    public Result list(Integer channel, Integer type, Integer status,
                       @RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "10") Integer pageSize){
        PageResult<Activity> pageResult = activityService.list(channel, type, status, page, pageSize);
        log.info("列表查询" + channel + "-" + type + "-" + status + "-" + page + "-" + pageSize);
        return Result.success(pageResult);
    }
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id) {
        activityService.delete(id);
        return Result.success();
    }

    @PostMapping
    public Result add(@RequestBody Activity activity){
        activityService.add(activity);
        return Result.success();
    }
    @GetMapping("/{id}")
    public Result getByID(@PathVariable Integer id) {
        return Result.success(activityService.getByID(id));
    }
    @PutMapping
    public Result update(@RequestBody Activity activity) {
        activityService.update(activity);
        return Result.success();
    }
    @GetMapping("/type/{type}")
    public Result getByType(@PathVariable Integer type) {
        return Result.success(activityService.getByType(type));
    }
}
